﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;

namespace DigDes.DS2012.Infrastructure
{
    public static class AppConfig
    {
        public static SqlConnection GetConnection()
        {
            try
            {
                var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["RailwayDatabase"].ConnectionString);
                return connection;
            }
            catch (Exception ex)
            {
                throw new ConfigurationErrorsException("Ошибка конфигурации системы. Обратитесь к администратору системы.", ex);
            }
        }

        /// <summary>
        /// Стандартное время выполнения запроса к БД в секундах
        /// </summary>
        public static int CommandTimeout 
        { 
            get
            {
                var timeoutSetting = ConfigurationManager.AppSettings["Database.CommandTimeout"];
                int result;
                if (Int32.TryParse(timeoutSetting, out result))
                    return result;
                else
                    return 30;
            }
        }

        public static string DataLoadersFolder
        {
            get
            {
                return ConfigurationManager.AppSettings["DataLoadersFolder"];
            }
        }
    }
}
